/*
 * @Author: 清香白莲 1243327527@qq.com
 * @Date: 2023-08-11 16:19:56
 * @LastEditors: 清香白莲 1243327527@qq.com
 * @LastEditTime: 2023-09-12 15:25:46
 * @FilePath: /shang_study/src/router/index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from "vue"
import VueRouter from "vue-router"

// 使用插件
Vue.use(VueRouter)

import routes from './routes'

let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;

/*
重写push方法
成功resolve
失败reject
*/
VueRouter.prototype.push = function(location, resolve, reject) {
    if (resolve && reject) {
        originPush.call(this, location, resolve, reject)
    }else {
        originPush.call(this, location, () => {
            console.log('成功了')
        }, () => {
            console.log('失败了')
        })
    }
}
VueRouter.prototype.replace = function(location, resolve, reject) {
    if (resolve && reject) {
        originReplace.call(this, location, resolve, reject)
    }else {
        originReplace.call(this, location, () => {
            
        }, () => {
            
        })
    }
}

const router =  new VueRouter({
    routes,
    scrollBehavior (to, from, savedPosition) {
        return { x: 0, y: 0 }; // 将页面滚动到顶部
    }
})

export default router